package com.handsure.xixili.util;

import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @author Cheng.Peng
 * @version 1.0
 * @time 2017/6/7 13:53
 * @Description TODO
 */
public class BaseTools {

    /**
     * 获取系统时间
     *
     * @return
     * @throws ParseException
     */
    public static Date systemtime() {
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String dateString = formatter.format(date);
        ParsePosition pos = new ParsePosition(0);
        Date currenttime = formatter.parse(dateString, pos);
        return currenttime;
    }


    /**
     * 获取系统时间long
     *
     * @return
     * @throws ParseException
     */
    public static long systemtimeLong() {
        return new Date().getTime();
    }

    /**
     * 转换数据库long型日期至字符串类型
     * @param millsec
     * @return
     */
    public static String formateMillsecDateToStr(long millsec){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.CHINA);
        Date date= new Date(millsec);
        return formatter.format(date);
    }


}
